

#include "CompileConfig.h"
#include "ThreadHelper.h"

#if _Platform_Windows_
#include <windows.h>
#endif

namespace FlameEngine
{

#if _Platform_Windows_ && _Compiler_VS_
	//code from:
	//http://blogs.msdn.com/b/stevejs/archive/2005/12/19/505815.aspx
	typedef struct tagTHREADNAME_INFO
	{
		DWORD dwType; // must be 0x1000
		LPCSTR szName; // pointer to name (in user addr space)
		DWORD dwThreadID; // thread ID (-1=caller thread)
		DWORD dwFlags; // reserved for future use, must be zero
	} THREADNAME_INFO;

#endif

	void ThreadHelper::SetThreadName(char* pName)
	{
#if _Platform_Windows_ && _Compiler_VS_

		THREADNAME_INFO info;
		info.dwType = 0x1000;
		info.szName = pName;
		info.dwThreadID = -1;
		info.dwFlags = 0;

		__try
		{
			RaiseException(0x406D1388, 0, sizeof(info) / sizeof(DWORD), (DWORD*)&info);
		}
		__except (EXCEPTION_CONTINUE_EXECUTION)
		{
		}
#endif
	}
}